<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    *{
        margin: 0;
        padding: 0;
        list-style: none;
        box-sizing: border-box;
    }
    .box{
        width: 600px;
       
        margin: 0 auto;
    }
    ul{
        border: 1px solid red;
        display: flex;
        flex-wrap: wrap;
        padding: 20px;
        justify-content: space-between;
    }
    ul li {
        width: 24%;
        border: 1px solid #000;
    }
    li img{
        opacity: 0.5;
    }
</style>
<body>
    <div class="box">
        <ul>
            <li><img src="./1.jpg" alt=""></li>
            <li><img src="./1.jpg" alt=""></li>
            <li><img src="./1.jpg" alt=""></li>
            <li><img src="./1.jpg" alt=""></li>
            <li><img src="./1.jpg" alt=""></li>
            <li><img src="./1.jpg" alt=""></li>
            <li><img src="./1.jpg" alt=""></li>
            <li><img src="./1.jpg" alt=""></li>
        </ul>
    </div>
</body>
</html>
<script>
    var img=document.querySelectorAll('img')
    for(var i=0;i<img.length;i++){
        img[i].onmouseover=function(){
            this.style.opacity=1
        }
        img[i].onmouseout=function(){
            this.style.opacity=0.5
        }
    }
</script>